package com.ggleaf.spdemo.controller;

import com.ggleaf.spdemo.bean.Good;
import com.ggleaf.spdemo.service.CouponService;
import com.ggleaf.spdemo.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/good")
public class GoodPriceController {

    @Autowired
    private GoodService goodService;

    @Autowired
    private CouponService couponService;

    @RequestMapping("/getPrice")
    public Double getPrice(Long goodId,String couponType){
        // 查询商品
        Good good = goodService.selectGoodById(goodId);
        if (good==null){
            throw new RuntimeException("参数有误，未查询到商品");
        }
        Double goodPrice =  good.getPrice();

        Double finalPrice = PriceUtil.discountPriceByCouponType(goodPrice,couponType);





        return finalPrice;
    }



}
